<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
use think\Db;
use think\Session;


function userarray(){//会员数据

     $userid=Session::get('userid');
	  $user=Db::name('member')->where('id',$userid)->find();
	  return $user;
}
function suminviter($name){

 $sum= Db::name('member')->field('name')->order('id desc')->where('inviter',$name)->count();
 return $sum;
}
//结算反点
function projectfd($money,$id,$confbl,$arrf,$fool='0'){
     if($fool>9){return ;}//10及返回
      $userid=$id;
	  $arr=explode(',',$confbl);
	  if(empty($arr[$fool])){return ;}//未设置比例结束
	  $user=Db::name('member')->field('inviter')->where('id',$userid)->find();
	  if(empty($user['inviter'])){return;}//没有推荐人就结束
	  else{
        $moneyf=$money*$arr[$fool]/100; $fool++;
        Db::name('member')->where('id',$user['inviter'])->setInc('amount',$moneyf);//添加金额
        addmoneylog($user['inviter'],"第".$fool."代下级,充值金额返点!",$moneyf,'+','1',$arrf);//添加金额记录
        projectfd($money,$user['inviter'],$confbl,$arrf,$fool);//递归
	  }
}
//在线充值








//








//算下级总人数
function memberxj($id){
 $num=Db::name('member')->order('id desc')->field('name,id,regtime')->where('inviter',$id)->count();
return $num;
}

function msgstater($state){//信件状态

  if($state=='1'){return '<font color="#00A11D">已读</font>';}else{
  return '<font color="red">未读</font>';
  
  }
}
function msgpic($state){
if($state=='1'){return 'read';}else{
  return 'xf1';
}
}
function userdj($id){//会员等级

     
	  $user=Db::name('memberdj')->where('id',$id)->find();
	  return $user['name'];
}



function sumorderfh($id){//收益

	  $money=Db::name('moneylog')->where("userid='".$id."' and notice like '%分红%'")->sum('money');
	  return $money;
}
function sumorderbj($id){//收益

      // $id=Session::get('userid');
	  $money=Db::name('moneylog')->where("userid='".$id."' and notice like '%本金%'")->sum('money');
	  return $money;
}

function sumnews($id){//信件

       
	  $count=Db::name('news')->where("(uid='".$id."' ) and stater='0'")->count();
	  return $count;
}


function stimedays($time,$day){//获取剩余天数

	$time=strtotime($time);
	$dqtime=time();
	$day=ceil($day-($dqtime-$time)/24/60/60);
	if($day<0){$day="<font color='red'>0</font>";}
return $day;

}
function prmoneybfb($zcmoey,$money){
	
	return $zcmoey/$money*100;
  

}
function usermoney($userid){
$user=Db::name('member')->where('id',$userid)->find();
	  return $user['money'];

}

function fkfs($type){
if($type=="1"){
 return "按周期付收益，到期还本";
}else{
return "按日付收益，到期还本";
}
}
function sfft($type){
if($type=="0"){
 return "可复投";
}else{
return "不可复投";
}
}
function sumorderlist(){

$userid=Session::get('userid');
$money=Db::name('orderlist')->where("userid",$userid)->sum('money');
return $money;
}
function sumzczmoney(){

$userid=Session::get('userid');
$money=Db::name('paylist')->where("userid='".$userid."' and state='1'")->sum('money');
return $money;

}

function sumorder($order){
	
      foreach($order as $key=>$vaf){
		 $order[$key]['ymoney']= Db::name('orderlist')->where("projectid",$vaf['id'])->sum('money');
		 $order[$key]['jdt']= round(($order[$key]['xuni_price']+$order[$key]['ymoney'])/$vaf['money']*100,2); 
         if( $order[$key]['jdt']>100){ $order[$key]['jdt']="100";}
         
		}
		return $order;
}
function sumorderf($order){
	$arr=array();
      foreach($order as $key=>$vaf){
		  $arr[$key]=$vaf;
		 $arr[$key]['ymoney']= Db::name('orderlist')->where("projectid",$vaf['id'])->sum('money');
		 $arr[$key]['jdt']= round(($arr[$key]['xuni_price']+$arr[$key]['ymoney'])/$vaf['money']*100,2);
		}
		return $arr;
}
function webstatusdd($state,$id=''){

if($state=='1'){
 return '众筹中';
}elseif($state=='2'){
 return '出售中';
}elseif($state=='3'){
 return '投票中';
}elseif($state=='4'){
 return '待回款';
}elseif($state=='5'){
 return '已完成';
}
elseif($state=='5' and $sfhg=='1'){
 return '溢价回购';
}
return "预热中";
}
function webstatusf($state,$id=''){
if($state=='1'){
 return '温馨提示：该项目还未进入投票中,不允许投票';
}elseif($state=='2'){
 return '温馨提示：该项目还未进入投票中,不允许投票';
}elseif($state=='3'){
 return '<a  href="/index/user/projetp/id/'.$id.'" class=" btn"  >点击投票</a>';
}elseif($state=='4'){
 return '待回款';
}elseif($state=='5'){
 return '已完成';
}

}
function webstatusp($state,$id='',$idf='',$idff=''){
if($state=='1'){
 return '众筹中';
}elseif($state=='2'){
 return '出售中';
}elseif($state=='3'){
	if($idff=='1' and $idf=='1'){return "<font color='green'>已赞成</font>";}
	elseif($idff=='1' and  $idf=='0'){return "<font color='red'>未赞成</font>";}
 return '<a  href="/index/user/projetp/id/'.$id.'" class=" btn"  >点击投票</a>';
}elseif($state=='4'){
 return '待回款';
}elseif($state=='5'){
 return '<font color="green">已完成</font>';
}

}


//短信接口
function sendmsm($http,$uid,$pwd,$mobile,$content,$time=''){

    $data = array
      (
      'Action'=>'SendMessage',
      'UserId'=>$uid,             //用户账号
      'UserPwd'=>$pwd,      //MD5位32密码,小写
      'SendPhone'=>$mobile,           //号码
      'SendMessage'=>$content,      //内容
      );
	  $url=$http."?";
    foreach($data as $key=>$va){
	$url.=$key."=".$va."&";
	
	}
 
	$url=trim($url,'&');
	$date=file_get_contents($url);
  //$date=file($url);dump($date);die;
	return $date;
    
  }
function curlget($url){
  //初始化
 
  $curl = curl_init();dump($curl);die;
  //设置抓取的url
  curl_setopt($curl, CURLOPT_URL,$url);
  curl_setopt($curl, CURLOPT_HEADER, 1);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  $data = curl_exec($curl);print_r($data);die;
   curl_close($curl);
  return $data;

}

function projectstatuswab($type){//状态
  if($type=='1'){
   return "<span class='red'>[已结束]          </span>";
  }else{
	  return "<font color=' green'>[投资中]</font>";
  }

}
  //短信

  function sendsmsfs($mobile)
    {
        $str='0123456789';
$len=strlen($str)-1;
$randstr='';
for($i=0;$i<6;$i++){
$num=mt_rand(0,$len);
$randstr .= $str[$num];
}    $config= Db::name('config')->find();
		
		 $post=input("post.");
   $PHONE=$mobile;
   $CONTENT=$config['dxmb']."您的密码已重置成功，新的密码为：".$randstr.",请您妥善保管。";
    $http = 'http://api.eait.cn/Sms/SmsHttp_U.aspx';    //短信接口
    $uid = $config['dxname'];              //用户账号
    $pwd = $config['dxpwd'];              //密码
    $time = '';
    $result = sendmsm($http,$uid,$pwd,$PHONE,$CONTENT,$time);
	$arr=explode(',',$result);
	$result=$result[0];
	Session::set('yzm',$randstr);
	if($result=='1'){
	return $randstr;}else{
	return false;
	}
		
       

    }
